// pages/contactus/contactus.js
const api = require('../../utils/api.js')
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    siteInfo: {},
    title: '',
    mobile: '',
    contacts: '',
    address: '',
    description: '',
    latitude: '',
    longitude: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      siteInfo: app.globalData.siteInfo,
      title: app.globalData.siteInfo.name,
      mobile: app.globalData.siteInfo.mobile,
      contacts: app.globalData.siteInfo.contacts,
      address: app.globalData.siteInfo.address,
      description: app.globalData.siteInfo.description,
      latitude: app.globalData.siteInfo.latitude,
      longitude: app.globalData.siteInfo.longitude
    })

    wx.setNavigationBarTitle({
      title: this.data.title
    })
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.getStorage({
      key: "contactus_bottom",
      success: function (res) {
        if (res.data=="1"){
          wx.pageScrollTo({
            scrollTop: 800,
          })
          wx.removeStorage({ key: "contactus_bottom"});
        }
      } 
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: this.data.title,
      path: '/pages/contactus/contactus'
    }
  },
  callPhone:function(){
    wx.makePhoneCall({
      phoneNumber: this.data.mobile,
    })
  },
  addPhone:function(){
    wx.addPhoneContact({
      firstName: app.globalData.siteInfo.contacts,//联系人姓名 
      weChatNumber: app.globalData.siteInfo.mobile, 
      mobilePhoneNumber: app.globalData.siteInfo.mobile,//联系人手机号  
      //addressState:"内蒙",
      //addressCity:"兴和县",
      addressStreet: this.data.address,
      organization: this.data.title,
      //email:"2459501893@qq.com",
      //title:"总经理"
    })  
  }
})